package com.hxd.otc.module.fiat_deal.presenter;

import android.support.annotation.NonNull;

import com.hxd.otc.R;
import com.hxd.otc.base.BaseBean;
import com.hxd.otc.module.fiat_deal.bean.DealResultDataBean;
import com.hxd.otc.module.fiat_deal.contract.DealDialogContract;
import com.hxd.otc.module.my.bean.BankCardBean;
import com.hxd.otc.module.my.model.BankModel;
import com.hxd.otc.mvp.base.BasePresenter;
import com.hxd.otc.net.BaseObserver;
import com.hxd.otc.utils.ResourceUtil;

import java.util.ArrayList;

/**
 * Created by lzy on 2018/11/22 0022.
 * description ${交易对话框 Presenter}
 */
public class DealDialogPresenter extends BasePresenter<DealDialogContract.IView> implements DealDialogContract.IPresenter {
    private final BankModel mBankModel;
    private DealResultDataBean.Data mDealData;
    private int mDealType;
    private String mTransactionPair;
    private ArrayList<BankCardBean> mBankCardBeans;
    private BankCardBean mSelBankCardBean;

    public DealDialogPresenter(DealDialogContract.IView iView) {
        super(iView);
        mBankModel = BankModel.getInstance();
    }

    @Override
    public DealResultDataBean.Data getDealData() {
        return mDealData;
    }

    @Override
    public void setDealData(DealResultDataBean.Data dealData) {
        mDealData = dealData;
    }

    @Override
    public int getDealType() {
        return mDealType;
    }

    @Override
    public void setDealType(int dealType) {
        mDealType = dealType;
    }

    @Override
    public String getTransactionPair() {
        return mTransactionPair;
    }

    @Override
    public void setTransactionPair(String transactionPair) {
        mTransactionPair = transactionPair;
    }

    @Override
    public void getUserBankCard() {
        mBankModel.getUserBankCardByOrderId(mDealData.id, new BaseObserver<ArrayList<BankCardBean>>() {
            @Override
            public void onNext(@NonNull String msg, @NonNull ArrayList<BankCardBean> bankCardBeans) {
                mBankCardBeans = bankCardBeans;
                if (mBankCardBeans == null || mBankCardBeans.size() == 0) return;
                mView.updateSelBankCard(mBankCardBeans.get(0));
            }

            @Override
            public void onError(int errType, @NonNull String errMessage) {
                mView.getUserBankCardFail(errMessage);
            }
        }, mView.<BaseBean<ArrayList<BankCardBean>>>bindAutoDispose());
    }

    @Override
    public ArrayList<BankCardBean> getBankCardList() {
        if (mBankCardBeans == null) {
            mView.showToast(ResourceUtil.getString(R.string.we_are_trying_to_retrieve_the_collection_method_information_for_you));
            getUserBankCard();
        }
        return mBankCardBeans;
    }

    @Override
    public void setSelBankCard(BankCardBean bankCardBean) {
        mSelBankCardBean = bankCardBean;
    }

    @Override
    public BankCardBean getSelBankCardBean() {
        return mSelBankCardBean;
    }
}
